package com.alibaba.citrus.cr.mn.order.center.facade.repository.impl;

import com.alibaba.citrus.cr.mn.order.center.facade.repository.DealLineWriteRepository;
import com.epoch.app.crforecastsales.domian.deallinequeue.model.DealLineQueue;
import com.epoch.app.crforecastsales.domian.deallinequeue.service.DealLineQueueService;
import com.epoch.app.crforecastsales.model.dto.DealLineSDO;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;
import java.util.List;

@Service("dealLineWriteRepositoryImplBiz")
public class DealLineWriteRepositoryImpl implements DealLineWriteRepository {
    @Resource
    DealLineQueueService dealLineQueueService;
    /**
     * 创建处理行信息
     *
     * @param dealLineSDOS
     */
    @Override
    public boolean batchCreate(List<DealLineSDO> dealLineSDOS) {
        for (DealLineSDO dealLineSDO : dealLineSDOS) {
            DealLineQueue dealLineQueue=new DealLineQueue();
            dealLineQueue.setBatchNumber(dealLineSDO.getBatchNumber());
            dealLineQueue.setContent(dealLineSDO.getContent());
            dealLineQueue.setCreator(dealLineSDO.getCreator());
            dealLineQueue.setDealStatus(dealLineSDO.getDealStatus());
            dealLineQueue.setDealTime(dealLineSDO.getDealTime());
            if (!ObjectUtils.isEmpty(dealLineSDO.getDealType())){
                dealLineQueue.setDealType(Integer.parseInt(dealLineSDO.getDealType()));
            }

            dealLineQueue.setForecastOrderLineId(dealLineSDO.getForecastOrderLineId());
//            dealLineQueue.setGmtCreate(dealLineSDO.getGmt_create());
            dealLineQueue.setGmt_create(dealLineSDO.getGmt_create());
            //dealLineQueue.setGmtModified(dealLineSDO.getGmtModified());
            dealLineQueue.setUpdater(dealLineQueue.getUpdater());
            dealLineQueue.setStatus(dealLineSDO.getStatus());
            dealLineQueueService.createDealLineQueue(dealLineQueue);
        }
        return true;
    }

    @Override
    public boolean update(DealLineQueue dealLineSDO) {
        Object o = dealLineQueueService.updateDealLineQueue(dealLineSDO);
        return true;
    }

    @Override
    public boolean batchUpdate(List<DealLineQueue> collect) {
        for (DealLineQueue dealLineQueue : collect) {
            Object o = dealLineQueueService.updateDealLineQueue(dealLineQueue);
        }
        return true;
    }
}
